package org.vgou.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 
 * Copyright (c) 2011, vgou All rights reserved.
 * 
 * @since Nov 27, 2011
 * @author <a href="mailto:jason.hxx@gmail.com">jason</a>
 * @version Id: Location.java Nov 27, 2011
 * @comment 地区实体类
 * 
 */
@Entity
// 更新一个对象时,会生成动态SQL,当属性值发生变化时，才会包含到UPDATE语句中
@org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
@Table(name = "location")
public class Location implements Serializable {

	private static final long serialVersionUID = 6667520617884018610L;

	/** 唯一主键 * */
	@Id
	@GeneratedValue
	@Column(name = "id", length = 19)
	private long id;
	
	/** 地区名称 **/
	@Column(name = "name", nullable=false)
	private String name;
	
	/** 父级地区 **/
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="parentid")
	private Location parent;
	
	/** 子级地区集合 **/
	@OneToMany(mappedBy="parent",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	private Set<Location> children = new HashSet<Location>();
	
	public Location() {
		super();
	}

	public Location(long id, String name, Location parent) {
		super();
		this.id = id;
		this.name = name;
		this.parent = parent;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Location getParent() {
		return parent;
	}

	public void setParent(Location parent) {
		this.parent = parent;
	}

	public Set<Location> getChildren() {
		return children;
	}

	public void setChildren(Set<Location> children) {
		this.children = children;
	}

}
